home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / misc / ReportPlus.lha / reportplus / source / f7.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-23  |  24.0 KB  |  681 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <libraries/gadtools.h>
  6. #include <dos/dosextens.h>
  7. #include <graphics/gfx.h>
  8.  
  9. #include <clib/exec_protos.h>
  10. #include <clib/intuition_protos.h>
  11. #include <clib/gadtools_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/graphics_protos.h>
  14.  
  15. #define ALL_REACTION_CLASSES
  16. #define ALL_REACTION_MACROS
  17. #include <reaction/reaction.h>
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "rp.h"
  23.  
  24. #define AMIGA 0
  25. #define MAC   1
  26. #define IBM   2
  27.  
  28. // from rp.c
  29. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  30. IMPORT ABOOL               fillwindows, stop;
  31. IMPORT SBYTE               page;
  32. IMPORT SWORD               y;
  33. IMPORT TEXT                asldir[PATHNAMEFIELD + 1];
  34. IMPORT ULONG               fillcolour;
  35. IMPORT struct NewGadget    Gadget;
  36. IMPORT struct Window*      MainWindowPtr;
  37. IMPORT struct Screen*      ScreenPtr;
  38. IMPORT struct IconBase*    IconBase;
  39. IMPORT struct SharedStruct shared;
  40. IMPORT Object*             WinObject[FUNCTIONS + 1];
  41. IMPORT struct Menu*        MenuPtr;
  42.  
  43. MODULE struct
  44. {   ULONG detabulate, unwrap, source, dest, tabsize;
  45.     TEXT  pathname[PATHNAMEFIELD + 1];
  46. } eol =
  47. {   FALSE, FALSE, IBM, AMIGA, 8, ""
  48. };
  49.  
  50. AGLOBAL struct Gadget* eol_gadgets[GIDS_7 + 1];
  51.  
  52. MODULE STRPTR EOLOptions[4] =
  53. {   (STRPTR) "LF (Amiga)",
  54.     (STRPTR) "CR (Macintosh)",
  55.     (STRPTR) "CR+LF (IBM-PC)",
  56.     NULL
  57. };
  58.  
  59. MODULE ABOOL spaceeol(TEXT nextchar);
  60.  
  61. AGLOBAL void eol1(void)
  62. {   struct Hook Hook7Struct;
  63.  
  64.     InitHook(&Hook7Struct, Hook7Func, NULL);
  65.  
  66.     /* Create the window object. */
  67.     lockscreen();
  68.     if (!(WinObject[7] =          NewObject(WINDOW_GetClass(), NULL,
  69.     // window
  70.     WA_PubScreen,                 ScreenPtr,
  71.     WA_ScreenTitle,               "Report+",
  72.     WA_Title,                     "Report+: EOL/Tab Converter",
  73.     WA_Activate,                  TRUE,
  74.     WA_DepthGadget,               TRUE,
  75.     WA_DragBar,                   TRUE,
  76.     WA_CloseGadget,               TRUE,
  77.     WA_SizeGadget,                TRUE,
  78.     WA_IDCMP,                     IDCMP_RAWKEY,
  79.     WINDOW_IDCMPHook,             &Hook7Struct,
  80.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  81.     WINDOW_MenuStrip,             MenuPtr,
  82.     WINDOW_Position,              WPOS_CENTERSCREEN,
  83.     WINDOW_ParentGroup,           eol_gadgets[GID_7_LY1] =
  84.                                   NewObject(LAYOUT_GetClass(), NULL,
  85.         // root-layout
  86.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  87.         LAYOUT_SpaceOuter,        TRUE,
  88.         LAYOUT_DeferLayout,       TRUE,
  89.         LAYOUT_AddChild,
  90.         NewObject
  91.         (   LAYOUT_GetClass(),    NULL,
  92.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  93.             LAYOUT_SpaceOuter,    TRUE,
  94.             LAYOUT_VertAlignment, LALIGN_CENTER,
  95.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  96.             LAYOUT_BevelStyle,    BVS_NONE,
  97.             LAYOUT_AddChild,
  98.             NewObject
  99.             (   LAYOUT_GetClass(),    NULL,
  100.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  101.                 LAYOUT_SpaceOuter,    TRUE,
  102.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  103.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  104.                 LAYOUT_BevelStyle,    BVS_FIELD,
  105.                 LAYOUT_AddImage,          NewObject
  106.                 (   LABEL_GetClass(),     NULL,
  107.                     LABEL_Text,           "_Source:",
  108.                     LABEL_Justification,  LJ_CENTER,
  109.                 TAG_END),
  110.                 CHILD_WeightedHeight,     0,
  111.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA1] =
  112.                 NewObject
  113.                 (   RADIOBUTTON_GetClass(),NULL,
  114.                     GA_ID,                GID_7_RA1,
  115.                     GA_RelVerify,         TRUE,
  116.                     GA_Text,              EOLOptions,
  117.                     RADIOBUTTON_Selected, (WORD) eol.source,
  118.                 TAG_END),
  119.             TAG_END),
  120.             CHILD_WeightedWidth,      50,
  121.             LAYOUT_AddChild,
  122.             NewObject
  123.             (   LAYOUT_GetClass(),    NULL,
  124.                 LAYOUT_Orientation,   LAYOUT_ORIENT_VERT,
  125.                 LAYOUT_SpaceOuter,    TRUE,
  126.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  127.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  128.                 LAYOUT_BevelStyle,    BVS_FIELD,
  129.                 LAYOUT_AddImage,          NewObject
  130.                 (   LABEL_GetClass(),     NULL,
  131.                     LABEL_Text,           "_Destination:",
  132.                     LABEL_Justification,  LJ_CENTER,
  133.                 TAG_END),
  134.                 CHILD_WeightedHeight,     0,
  135.                 LAYOUT_AddChild,          eol_gadgets[GID_7_RA2] =
  136.                 NewObject
  137.                 (   RADIOBUTTON_GetClass(),NULL,
  138.                     GA_ID,                GID_7_RA2,
  139.                     GA_RelVerify,         TRUE,
  140.                     GA_Text,              EOLOptions,
  141.                     RADIOBUTTON_Selected, (WORD) eol.dest,
  142.                 TAG_END),
  143.             TAG_END),
  144.             CHILD_WeightedWidth,      50,
  145.         TAG_END),
  146.         LAYOUT_AddChild,
  147.         NewObject
  148.         (   LAYOUT_GetClass(),    NULL,
  149.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  150.             LAYOUT_SpaceOuter,    TRUE,
  151.             LAYOUT_VertAlignment, LALIGN_CENTER,
  152.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  153.             LAYOUT_BevelStyle,    BVS_NONE,
  154.             LAYOUT_AddChild,          eol_gadgets[GID_7_CB1] =
  155.             NewObject
  156.             (   CHECKBOX_GetClass(),  NULL,
  157.                 GA_ID,                GID_7_CB2,
  158.                 GA_RelVerify,         TRUE,
  159.                 GA_Text,              "C_onvert tabs to spaces?",
  160.                 GA_Selected,          (BOOL) eol.detabulate,
  161.             TAG_END),
  162.             CHILD_WeightedWidth,      0,
  163.             LAYOUT_AddImage,
  164.             NewObject
  165.             (   LABEL_GetClass(),     NULL,
  166.                 LABEL_Text,           "",
  167.             TAG_END),
  168.             CHILD_WeightedWidth,      100,
  169.             LAYOUT_AddImage,
  170.             NewObject
  171.             (   LABEL_GetClass(),     NULL,
  172.                 LABEL_Text,           "_Tab size:",
  173.             TAG_END),
  174.             CHILD_WeightedWidth,      0,
  175.             LAYOUT_AddChild,          eol_gadgets[GID_7_IN1] =
  176.             NewObject
  177.             (   INTEGER_GetClass(),   NULL,
  178.                 GA_ID,                GID_7_IN1,
  179.                 GA_RelVerify,         TRUE,
  180.                 GA_TabCycle,          TRUE,
  181.                 INTEGER_Number,       eol.tabsize,
  182.                 INTEGER_Minimum,      0,
  183.                 INTEGER_Maximum,      99,
  184.                 INTEGER_MinVisible,   2,
  185.             TAG_END),
  186.             CHILD_WeightedWidth,      0,
  187.         TAG_END), 
  188.         CHILD_WeightedHeight,         0,
  189.         LAYOUT_AddChild,              eol_gadgets[GID_7_CB2] =
  190.         NewObject
  191.         (   CHECKBOX_GetClass(),      NULL,
  192.             GA_ID,                    GID_7_CB2,
  193.             GA_RelVerify,             TRUE,
  194.             GA_Text,                  "_Unwrap words?",
  195.             GA_Selected,              (BOOL) eol.unwrap,
  196.         TAG_END),
  197.         CHILD_WeightedHeight,         0,
  198.         LAYOUT_AddChild,
  199.         NewObject
  200.         (   LAYOUT_GetClass(),        NULL,
  201.             LAYOUT_Orientation,       LAYOUT_ORIENT_HORIZ,
  202.             LAYOUT_SpaceOuter,        TRUE,
  203.             LAYOUT_VertAlignment, LALIGN_CENTER,
  204.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  205.             LAYOUT_BevelStyle,    BVS_FIELD,
  206.             LAYOUT_AddImage,
  207.             NewObject
  208.             (   LABEL_GetClass(),     NULL,
  209.                 LABEL_Text,       "_Pathname(s):",
  210.                 LABEL_Justification,LJ_LEFT,
  211.             TAG_END),
  212.             LAYOUT_AddChild,      eol_gadgets[GID_7_ST1] =
  213.             NewObject
  214.             (   STRING_GetClass(), NULL,
  215.                 GA_ID,            GID_7_ST1,
  216.                 GA_RelVerify,     TRUE,
  217.                 STRINGA_TextVal,  eol.pathname,
  218.                 STRINGA_MinVisible,20,
  219.             TAG_END),
  220.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU1] =
  221.             NewObject
  222.             (   NULL,             "button.gadget",
  223.                 GA_ID,            GID_7_BU1,
  224.                 GA_RelVerify,     TRUE,
  225.                 BUTTON_AutoButton,BAG_POPFILE,
  226.             TAG_END),
  227.             CHILD_WeightedWidth,  0,
  228.         TAG_END),
  229.         CHILD_WeightedHeight,     0,
  230.         LAYOUT_AddChild,          eol_gadgets[GID_7_ST2] =
  231.         NewObject
  232.         (   STRING_GetClass(),    NULL,
  233.             GA_ReadOnly,          TRUE,
  234.             GA_ID,                GID_7_ST2,
  235.             STRINGA_TextVal,      "Ready.",
  236.         TAG_END),
  237.         CHILD_WeightedHeight,     0,
  238.         LAYOUT_AddChild,
  239.         NewObject
  240.         (   LAYOUT_GetClass(),    NULL,
  241.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  242.             LAYOUT_SpaceOuter,    TRUE,
  243.             LAYOUT_VertAlignment, LALIGN_CENTER,
  244.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  245.             LAYOUT_BevelStyle,    BVS_NONE,
  246.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU3] =
  247.                                   NewObject(NULL, "button.gadget",
  248.                 GA_ID,            GID_7_BU3,
  249.                 GA_RelVerify,     TRUE,
  250.                 GA_Text,          "Pro_cess",
  251.             TAG_END),
  252.             CHILD_WeightedWidth,  50,
  253.             LAYOUT_AddChild,      eol_gadgets[GID_7_BU4] =
  254.                                   NewObject(NULL, "button.gadget",
  255.                 GA_ID,            GID_7_BU4,
  256.                 GA_RelVerify,     TRUE,
  257.                 GA_Text,          "Stop",
  258.                 GA_Disabled,      TRUE,
  259.             TAG_END),
  260.             CHILD_WeightedWidth,  50,
  261.         TAG_END),
  262.         CHILD_WeightedHeight,     0,
  263.     TAG_END)
  264.     )))
  265.     {   rq("Can't create ReAction objects!");
  266.     }
  267.     unlockscreen();
  268.     openwindow();
  269.     ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  270.  
  271.     loop();
  272.     closewindow();
  273. }
  274.  
  275. AGLOBAL void eol_do(void)
  276. {   STRPTR stringptr;
  277.  
  278.     if (!(GetAttr
  279.     (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  280.     )))
  281.     {   rq("Unsupported inquiry!"); // should never happen
  282.     }
  283.     strcpy(eol.pathname, stringptr);
  284.     if (!(GetAttr
  285.     (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  286.     )))
  287.     {   rq("Unsupported inquiry!"); // should never happen
  288.     }
  289.  
  290.     SetGadgetAttrs
  291.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  292.         GA_Disabled, FALSE,
  293.     TAG_END);
  294.     SetGadgetAttrs
  295.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  296.         GA_Disabled, TRUE,
  297.     TAG_END);
  298.     SetGadgetAttrs
  299.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  300.         GA_Disabled, TRUE,
  301.     TAG_END);
  302.     SetGadgetAttrs
  303.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  304.         GA_Disabled, TRUE,
  305.     TAG_END);
  306.     SetGadgetAttrs
  307.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  308.         GA_Disabled, TRUE,
  309.     TAG_END);
  310.     SetGadgetAttrs
  311.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  312.         GA_Disabled, TRUE,
  313.     TAG_END);
  314.     SetGadgetAttrs
  315.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  316.         GA_Disabled, TRUE,
  317.     TAG_END);
  318.     SetGadgetAttrs
  319.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  320.         GA_Disabled, TRUE,
  321.     TAG_END);
  322.     SetGadgetAttrs
  323.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  324.         GA_Disabled, TRUE,
  325.     TAG_END);
  326.  
  327.     strcpy(shared.pathname, eol.pathname);
  328.     convert(TRUE);
  329.     strcpy(eol.pathname, shared.pathname);
  330.  
  331.     if (!stop)
  332.     {   SetGadgetAttrs
  333.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  334.             STRINGA_TextVal, "All done.",
  335.         TAG_END);
  336.     }
  337.     SetGadgetAttrs
  338.     (   eol_gadgets[GID_7_BU4], MainWindowPtr, NULL,
  339.         GA_Disabled, TRUE,
  340.     TAG_END);
  341.     SetGadgetAttrs
  342.     (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  343.         GA_Disabled, FALSE,
  344.     TAG_END);
  345.     SetGadgetAttrs
  346.     (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  347.         GA_Disabled, FALSE,
  348.     TAG_END);
  349.     SetGadgetAttrs
  350.     (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  351.         GA_Disabled, FALSE,
  352.     TAG_END);
  353.     SetGadgetAttrs
  354.     (   eol_gadgets[GID_7_BU1], MainWindowPtr, NULL,
  355.         GA_Disabled, FALSE,
  356.     TAG_END);
  357.     SetGadgetAttrs
  358.     (   eol_gadgets[GID_7_CB1], MainWindowPtr, NULL,
  359.         GA_Disabled, FALSE,
  360.     TAG_END);
  361.     SetGadgetAttrs
  362.     (   eol_gadgets[GID_7_CB2], MainWindowPtr, NULL,
  363.         GA_Disabled, FALSE,
  364.     TAG_END);
  365.     SetGadgetAttrs
  366.     (   eol_gadgets[GID_7_IN1], MainWindowPtr, NULL,
  367.         GA_Disabled, FALSE,
  368.     TAG_END);
  369.     SetGadgetAttrs
  370.     (   eol_gadgets[GID_7_BU3], MainWindowPtr, NULL,
  371.         GA_Disabled, FALSE,
  372.     TAG_END);
  373. }
  374.  
  375. AGLOBAL void eolconvert(ABOOL gui)
  376. {   ULONG                gap, i, j, cursorx = 0;
  377.     ABOOL                ok                 = TRUE;
  378.     struct FileInfoBlock InputInfoBlock;
  379.     UBYTE*               InputBufferPtr; // always use UBYTE not APTR for pointer arithmetic
  380.     BPTR                 FileHandle;
  381.     TEXT                 saystring[PATHNAMEFIELD + 1];
  382.  
  383.     strcpy(saystring, "Converting ");
  384.     strcat(saystring, shared.thisfile);
  385.     strcat(saystring, "...");
  386.     if (gui)
  387.     {   SetGadgetAttrs
  388.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  389.             STRINGA_TextVal, saystring,
  390.         TAG_END);
  391.     } else
  392.     {   Printf("%s", saystring);
  393.         Flush(Output());
  394.     }
  395.  
  396.     if (FileHandle = (BPTR) Lock(shared.thisfile, ACCESS_READ))
  397.     {   if (Examine(FileHandle, &InputInfoBlock))
  398.         {   UnLock(FileHandle);
  399.             // FileHandle = NULL;
  400.             if (InputInfoBlock.fib_DirEntryType == -3) // if a file
  401.             {   // if it is a directory, we would ideally like to convert all
  402.                 // files in that directory. We also should support links.
  403.                 if (InputBufferPtr = AllocMem(InputInfoBlock.fib_Size, MEMF_ANY | MEMF_PUBLIC))
  404.                 {   if (FileHandle = (BPTR) Open(shared.thisfile, MODE_OLDFILE))
  405.                     {   if (Read(FileHandle, InputBufferPtr, InputInfoBlock.fib_Size) != -1)
  406.                         {   Close(FileHandle);
  407.                             if (FileHandle = (BPTR) Open(shared.thisfile, MODE_NEWFILE))
  408.                             {   for (i = 0; i < InputInfoBlock.fib_Size; i++)
  409.                                 {   if (*(InputBufferPtr + i) == LF)
  410.                                     {   if (eol.unwrap && (eol.source == AMIGA || eol.source == IBM) && spaceeol(*(InputBufferPtr + i + 1)))
  411.                                         {   cursorx++;
  412.                                             FPutC(FileHandle, ' ');
  413.                                         } else
  414.                                         {   cursorx = 0;
  415.  
  416.                                             if (eol.source == eol.dest)
  417.                                                 FPutC(FileHandle, LF); // pass it through
  418.                                             elif (eol.source == AMIGA && eol.dest == IBM)
  419.                                             {   FPutC(FileHandle, CR); // add this
  420.                                                 FPutC(FileHandle, LF); // and pass this through
  421.                                             } elif (eol.source == AMIGA && eol.dest == MAC)
  422.                                                 FPutC(FileHandle, CR); // convert from LF to CR
  423.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  424.                                                 FPutC(FileHandle, LF); // pass it through
  425.                                             elif (eol.source == IBM && eol.dest == MAC)
  426.                                                 ; // do nothing
  427.                                             else ; // mac as source: we never expect LFs
  428.                                     }   }
  429.                                     elif (*(InputBufferPtr + i) == CR)
  430.                                     {   if (eol.unwrap && eol.source == MAC && spaceeol(*(InputBufferPtr + i + 1)))
  431.                                         {   cursorx++;
  432.                                             FPutC(FileHandle, ' ');
  433.                                         } else
  434.                                         {   cursorx = 0;
  435.  
  436.                                             if (eol.source == eol.dest)
  437.                                                 FPutC(FileHandle, CR); // pass it through
  438.                                             elif (eol.source == IBM && eol.dest == AMIGA)
  439.                                                 ; // do nothing
  440.                                             elif (eol.source == IBM && eol.dest == MAC)
  441.                                                 FPutC(FileHandle, CR); // pass it through
  442.                                             elif (eol.source == MAC && eol.dest == AMIGA)
  443.                                                 FPutC(FileHandle, LF); // convert from CR to LF
  444.                                             elif (eol.source == MAC && eol.dest == IBM)
  445.                                             {   FPutC(FileHandle, CR); // pass this through
  446.                                                 FPutC(FileHandle, LF); // and add this
  447.                                             } else ; // amiga as source: we never expect CRs
  448.                                     }   }
  449.                                     elif (*(InputBufferPtr + i) == TAB)
  450.                                     {   if (eol.detabulate)
  451.                                         {   gap = (((cursorx / eol.tabsize) + 1) * eol.tabsize) - cursorx;
  452.                                             for (j = 1; j <= gap; j++)
  453.                                                 FPutC(FileHandle, ' ');
  454.                                             cursorx += gap;
  455.                                         } else FPutC(FileHandle, TAB); // no point to cursorx in non-detabulate
  456.                                     } else
  457.                                     {   FPutC(FileHandle, *(InputBufferPtr + i));
  458.                                         cursorx++;
  459.                                 }   }
  460.                                 /* Note that FPutC() returns EOF for errors; this is not currently
  461.                                 checked. */
  462.                                 ok = TRUE;
  463.                                 Close(FileHandle);
  464.                         }   }
  465.                         else
  466.                         {   Close(FileHandle);
  467.                     }   }
  468.                     FreeMem(InputBufferPtr, InputInfoBlock.fib_Size);
  469.         }   }   }
  470.         else
  471.         {   UnLock(FileHandle);
  472.     }   }
  473.  
  474.     if (gui)
  475.     {   if (ok)
  476.             strcat(saystring, "done.");
  477.         else strcat(saystring, "failed!");
  478.  
  479.         SetGadgetAttrs
  480.         (   eol_gadgets[GID_7_ST2], MainWindowPtr, NULL,
  481.             STRINGA_TextVal, saystring,
  482.         TAG_END);
  483.     } else
  484.     {   if (ok)
  485.             Printf("done.\n");
  486.         else Printf("failed!\n");
  487.     }
  488.  
  489.     checkabort(gui);
  490. }
  491.  
  492. AGLOBAL void eol_loop(ULONG gid)
  493. {   STRPTR stringptr;
  494.  
  495.     switch(gid)
  496.     {
  497.     case GID_7_RA1:
  498.         if (!(GetAttr
  499.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA1], (ULONG *) &eol.source
  500.         )))
  501.         {   rq("Unsupported inquiry!"); // should never happen
  502.         }
  503.     break;
  504.     case GID_7_RA2:
  505.         if (!(GetAttr
  506.         (   RADIOBUTTON_Selected, eol_gadgets[GID_7_RA2], (ULONG *) &eol.dest
  507.         )))
  508.         {   rq("Unsupported inquiry!"); // should never happen
  509.         }
  510.     break;
  511.     case GID_7_ST1:
  512.         if (!(GetAttr
  513.         (   STRINGA_TextVal, eol_gadgets[GID_7_ST1], (ULONG *) &stringptr
  514.         )))
  515.         {   rq("Unsupported inquiry!"); // should never happen
  516.         }
  517.         strcpy(eol.pathname, stringptr);
  518.     break;
  519.     case GID_7_BU1:
  520.         strcpy(shared.pathname, eol.pathname);
  521.         multiasl("#?.info");
  522.         strcpy(eol.pathname, shared.pathname);
  523.         SetGadgetAttrs
  524.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  525.             STRINGA_TextVal, eol.pathname,
  526.             TAG_END
  527.         );
  528.     break;
  529.     case GID_7_BU3:
  530.         eol_do();
  531.     break;
  532.     case GID_7_CB1:
  533.         if (!(GetAttr
  534.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  535.         )))
  536.         {   rq("Unsupported inquiry!"); // should never happen
  537.         }
  538.     break;
  539.     case GID_7_CB2:
  540.         if (!(GetAttr
  541.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  542.         )))
  543.         {   rq("Unsupported inquiry!"); // should never happen
  544.         }
  545.     break;
  546.     case GID_7_IN1:
  547.         if (!(GetAttr
  548.         (   INTEGER_Number, eol_gadgets[GID_7_IN1], (ULONG *) &eol.tabsize
  549.         )))
  550.         {   rq("Unsupported inquiry!"); // should never happen
  551.         }
  552.     break;
  553.     default:
  554.     break;
  555. }   }
  556.  
  557. MODULE ABOOL spaceeol(TEXT nextchar)
  558. {   if
  559.     (   nextchar == ' '
  560.      || nextchar == TAB
  561.      || nextchar == LF
  562.      || nextchar == CR
  563.     )
  564.     {   return(FALSE);
  565.     } else return(TRUE);
  566. }
  567.  
  568. AGLOBAL void eol_die(void)
  569. {   IOBuffer[1] = (UBYTE) eol.source;
  570.     IOBuffer[2] = (UBYTE) eol.dest;
  571.     IOBuffer[3] = (UBYTE) eol.detabulate;
  572.     IOBuffer[4] = (UBYTE) eol.tabsize;
  573.     IOBuffer[5] = (UBYTE) eol.unwrap;
  574. }
  575.  
  576. AGLOBAL void eol_config(void)
  577. {   eol.source     = (ULONG) IOBuffer[1];
  578.     eol.dest       = (ULONG) IOBuffer[2];
  579.     eol.detabulate = (ULONG) IOBuffer[3];
  580.     eol.tabsize    = (ULONG) IOBuffer[4];
  581.     eol.unwrap     = (ULONG) IOBuffer[5];
  582. }
  583.  
  584. AGLOBAL ULONG Hook7Func(struct Hook *h, VOID *o, VOID *msg)
  585. {   /* "When the hook is called, the data argument points to the 
  586.     window object and message argument to the IntuiMessage." */
  587.  
  588.     UWORD code, qual;
  589.  
  590.     geta4(); // wait till here before doing anything
  591.  
  592.     code = ((struct IntuiMessage *) msg)->Code;
  593.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  594.  
  595.     switch(code)
  596.     {
  597.     case SCAN_HELP:
  598.         helpabout();
  599.     break;
  600.     case SCAN_ESCAPE:
  601.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  602.         {   cleanexit(EXIT_SUCCESS);
  603.         } else page = 0;
  604.     break;
  605.     case SCAN_D:
  606.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  607.         {   if (eol.dest < 2)
  608.                 eol.dest++;
  609.             else eol.dest = 0;
  610.         } else
  611.         {   if (eol.dest > 0)
  612.                 eol.dest--;
  613.             else eol.dest = 2;
  614.         }
  615.         SetGadgetAttrs
  616.         (   eol_gadgets[GID_7_RA2], MainWindowPtr, NULL,
  617.             RADIOBUTTON_Selected, eol.dest,
  618.         TAG_END);
  619.         // we must explicitly refresh
  620.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA2], MainWindowPtr, NULL);
  621.     break;
  622.     case SCAN_O:
  623.         // the gadget is handled automatically by the system, all we need
  624.         // to do is update our internal record of the state of the gadget
  625.         if (!(GetAttr
  626.         (   GA_Selected, eol_gadgets[GID_7_CB1], (ULONG *) &eol.detabulate
  627.         )))
  628.         {   rq("Unsupported inquiry!"); // should never happen
  629.         }
  630.     break;
  631.     case SCAN_P:
  632.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_ST1]);
  633.     break;
  634.     case SCAN_S:
  635.         if (!(qual & IEQUALIFIER_LSHIFT) && !(qual & IEQUALIFIER_RSHIFT))
  636.         {   if (eol.source < 2)
  637.                 eol.source++;
  638.             else eol.source = 0;
  639.         } else
  640.         {   if (eol.source > 0)
  641.                 eol.source--;
  642.             else eol.source = 2;
  643.         }
  644.         SetGadgetAttrs
  645.         (   eol_gadgets[GID_7_RA1], MainWindowPtr, NULL,
  646.             RADIOBUTTON_Selected, eol.source,
  647.         TAG_END);
  648.  
  649.         // we must explicitly refresh
  650.         RefreshGadgets((struct Gadget *) eol_gadgets[GID_7_RA1], MainWindowPtr, NULL);
  651.     break;
  652.     case SCAN_T:
  653.         ActivateLayoutGadget(eol_gadgets[GID_7_LY1], MainWindowPtr, NULL, (Object) eol_gadgets[GID_7_IN1]);
  654.     break;
  655.     case SCAN_U:
  656.         // the gadget is handled automatically by the system, all we need
  657.         // to do is update our internal record of the state of the gadget
  658.         if (!(GetAttr
  659.         (   GA_Selected, eol_gadgets[GID_7_CB2], (ULONG *) &eol.unwrap
  660.         )))
  661.         {   rq("Unsupported inquiry!"); // should never happen
  662.         }
  663.     break;
  664.     case SCAN_PERIOD:
  665.         strcpy(shared.pathname, eol.pathname);
  666.         multiasl("~(#?.info)");
  667.         strcpy(eol.pathname, shared.pathname);
  668.         SetGadgetAttrs
  669.         (   eol_gadgets[GID_7_ST1], MainWindowPtr, NULL,
  670.             STRINGA_TextVal, eol.pathname,
  671.         TAG_END);
  672.     break;
  673.     default:
  674.     break;
  675.     }
  676.  
  677.     return(1);
  678. }
  679.  
  680.  
  681.